package br.ita.battlefarm.moves;

import java.text.DecimalFormatSymbols;

import br.ita.battlefarm.core.Board;
import br.ita.battlefarm.core.Position;

public abstract class Move {
	
	protected int _allowedMoves = 0;
	protected int _backgroundRes;
	private boolean _isEnabled;
	
	public boolean isMoveEnabled(){
		return _isEnabled;
	}
	
	public void enableMove(){
		_isEnabled = true;
	}
	
	public void disableMove(){
		_isEnabled = false;
	}
	
	//Returns change in score
	public abstract int fire(Board board, int i, int j);
	
	public int getBackgroundRes(){
		return _backgroundRes;
	}
	
	public boolean hasMovesLeft(){
		return (_allowedMoves > 0 || _allowedMoves < 0);
	}
	
	public String getHowManyMovesLeftText(){
		if(_allowedMoves >= 0){
			return Integer.toString(_allowedMoves);
		}
		else{
			return (new DecimalFormatSymbols()).getInfinity();
		}
		
	}
	
	protected int fireInSquare(Board board, int line, int column) {
		int changeInScore = 0;
		if(board.validPlayPosition(line, column)){
			board.fire(line,column);
			Position firedPosition = new Position(line, column);
			if(board.getPieceThatOccupiesPosition(firedPosition) != null){
				changeInScore += 100;
			}
			else{
				changeInScore += -10;
			}
		}
		return changeInScore;
	}
}
